import axios from 'axios';

class Service {

    static loadDeviceType(callback) {
        return axios.get("/manage-api/device-type").then((data) => {
            callback ? callback(data) : null;
        })
    }

    static loadStoreAndDeviceType(callback) {
        return axios.all([axios.get("/manage-api/device-type"), axios.get("/manage-api/store")]).then(
            axios.spread(function (types, stores) {
                callback ? callback(types, stores) : null;
            })
        );
    }

    static saveDevice(devices, callback) {
        return axios.post("/manage-api/device", devices).then((data) => {
            callback ? callback(data) : null;
        });
    }

    static listDevice(baseQuery, callback) {
        return axios.post("/manage-api/list-device", baseQuery).then((data) => {
            callback ? callback(data) : null;
        });
    }

    static get(id, callback) {
        return axios.get("/manage-api/device/" + id).then((data) => {
            callback ? callback(data) : null;
        });
    }

    static remove(id, callback) {
        return axios.delete("/manage-api/device/" + id).then((data) => {
            callback ? callback(data) : null;
        });
    }
}

export default Service;